package com.czk.test;

import com.alibaba.fastjson.JSON;
import com.czk.client.ClientSocket;
import com.czk.future.SyncWrite;
import com.czk.msg.Request;
import com.czk.msg.Response;
import io.netty.channel.ChannelFuture;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/4/27 11:41
 */
public class StartClient {
    private static ChannelFuture channelFuture;

    public static void main(String[] args) throws Exception {
        ClientSocket clientSocket = new ClientSocket();
        new Thread(clientSocket).start();
        // 循环
        while (true) {
            if (channelFuture == null) {
                // 拿到
                channelFuture = clientSocket.getFuture();
                Thread.sleep(500);
                continue;
            }
            // 发送
            Request request = new Request();
            request.setObj("czk");
            SyncWrite syncWrite = new SyncWrite();
            Response response = syncWrite.writeAndSync(channelFuture.channel(), request, 1000);
            System.out.println("结果是" + JSON.toJSONString(response));
            Thread.sleep(1000);
        }


    }
}
